package com.ctrl.riveradministrator.mvp.view.activity.work_dynamic;

import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.os.Message;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.ctrl.riveradministrator.R;
import com.ctrl.riveradministrator.base.BaseActivity;
import com.ctrl.riveradministrator.base.BasePresenter;
import com.ctrl.riveradministrator.mvp.model.WorkDynamic;

public class WebActivity extends BaseActivity {

    private WebView webView;
    private WorkDynamic workDynamic;

    private Toolbar toolbar;
    private TextView titleTv, workTitle, workType, workState, workRemark;
    private ImageView leftMenu;

    @Override
    protected void initParams(Bundle parms) {
        workDynamic = (WorkDynamic) getIntent().getSerializableExtra("workdyn");
    }

    @Override
    protected int bindLayout() {
        return R.layout.activity_web;
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void initView(View view) {
        webView = (WebView) $(R.id.web);
        toolbar = (Toolbar) $(R.id.toolbar);
        titleTv = (TextView) $(R.id.title_tv);
        leftMenu = (ImageView) $(R.id.left_iv);
        workTitle = (TextView) $(R.id.title);
        workType = (TextView) $(R.id.type);
        workState = (TextView) $(R.id.state);
        workRemark = (TextView) $(R.id.remark);
        /*
         * 设置toolbar
         * */
        toolbar.setTitleTextColor(Color.WHITE);
        toolbar.setTitle("");
        titleTv.setText(workDynamic.getWorkTitle());
        leftMenu.setBackground(getDrawable(R.drawable.ic_chevron_left_24dp));
    }

    @Override
    protected void doBusiness(Context mContext) {
        workTitle.setText(workDynamic.getWorkTitle());
        workType.setText(workDynamic.getWorkTypeName());
        workState.setText(workDynamic.getStatusName());
        workRemark.setText(workDynamic.getRemark());
        webView.loadDataWithBaseURL(null, "<html>"
                + "<head>"
                + "<title></title>"
                + "</head>"
                + "<body>"
                + workDynamic.getWorkContent()
                + "</body>"
                + "</html>", "text/html", "utf-8", null);
    }

    @Override
    protected void widgetClick(View view) {
        switch (view.getId()) {
            case R.id.left_iv:
                finish();
                break;
        }
    }

    @Override
    protected void setListener() {
        leftMenu.setOnClickListener(this);
    }

    @Override
    public void handleMessage(Message message, int what) {

    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }
}
